<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>通用的js</title>
</head>
<body>
<p>输入框只能输入数字</p>
<input type="text" class="numberOnly">
</body>
<script src="../jquery/jquery.min.js"></script>
<script>
    $(function(){
        $('.numberOnly').keyup(function(){
            $(this).val($(this).val().replace(/\D|^0/g,''));
        });
    });
</script>
</html>